package com.dingqb.mycs.ui.activity;

import android.os.Bundle;
import android.widget.TextView;

import com.android.volley.Request.Method;
import com.android.volley.Response;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.base.AppApplication;
import com.base.BaseActivity;
import com.base.datacallback.VolleyCallBackListener;
import com.dingqb.mycs.R;

public class VolleryActivity extends BaseActivity implements VolleyCallBackListener {

	TextView tv_vollery_text;
	String tag = "abc_123";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_vollery_http);
		tv_vollery_text = (TextView) findViewById(R.id.tv_vollery_text);
		String url = "http://api.juheapi.com/japi/toh?key=d9c0b104852bb610edde357b1ece5327&v=1.0&month=12&day=8";
		// 请求的标识 数据 处理多个http请求的情况
		Bundle bundle = new Bundle();
		bundle.putString("tom", "i am tom");
		VolleryTask.getVollery(this, tag, url, bundle);
		// volleryGet(url,"adb_get");
	}

	@Override
	public void onFailure(Object object, Bundle bundle) {

	}

	@Override
	public void onSuccess(Object object, Bundle bundle) {
		tv_vollery_text.setText(object.toString() + bundle.getString("tom"));

	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		AppApplication.getHttpQueue().cancelAll(tag);
		System.out.println("cancerall");
	}

	void volleryGet(String url, String tag) {
		StringRequest request = new StringRequest(Method.GET, url, new Listener<String>() {

			@Override
			public void onResponse(String response) {
				tv_vollery_text.setText(response);
			}
		}, new Response.ErrorListener() {

			@Override
			public void onErrorResponse(VolleyError error) {
				tv_vollery_text.setText(error.toString());

			}
		});
		request.setTag(tag);
		AppApplication.getHttpQueue().add(request);
	}

}
